package com.wangzhen.codebase.thread.state;

/**
 * 线程中间演示
 */
public class ThreadInterruppt {

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            try {
                while (true) {
                    if (Thread.currentThread().isInterrupted()) {
                        System.out.println("thread is interrupted !!!");
                        break;
                    }
                    System.out.println("hello world is running");
                }
            } catch (Exception e) {
                if (e instanceof InterruptedException) {

                }
            }
        });

        t1.start();
        //t1.join();

        Thread.sleep(2000L);

        t1.interrupt();


        while (true) {
            Thread.sleep(100);
        }
    }
}
